import string
import numpy as np
from copy import deepcopy


# from logger import log

class Train:
    def __init__(self, id: string, initial_location):
        self.id = deepcopy(id)
        self.velocity = np.array([-40., 0., 0])
        self.initial_location = deepcopy(initial_location)
        self.velocity = deepcopy(self.velocity)
        self.out_of_battery = False
        self.location = [0, 0, 0]
        self.cache_state = []
        self.comp_resource = 2.5e9  # 列车计算资源，单位GHz
        self.MAX_X = 400
        self.MIN_X = 0

    def reset(self):
        self.location = deepcopy(self.initial_location)
        self.velocity = deepcopy(self.velocity)
        return self

    def move_train(self):
        # 火车在每个时隙内移动一次，速度保持恒定值
        self.location[0] += self.velocity[0]  # 仅更新横坐标

        # 检查横坐标是否超出边界
        if self.location[0] < self.MIN_X:
            self.location[0] = 0  # 列车位置更新到 x=0
            self.velocity[0] = -self.velocity[0]  # 反转横向速度
        elif self.location[0] > self.MAX_X:
            self.location[0] = 400  # 列车位置更新到 x=400
            self.velocity[0] = -self.velocity[0]  # 反转横向速度

    def cache_updating(self, UAVs):
        for uav in UAVs:
            if uav.comp_location == 1:
                self.cache_state.append(uav)


    def comp_time(self, task_complexity):
        # 计算任务的时间，假设计算时间与任务复杂度成正比
        # 假设计算速度是计算能力的一个函数，这里简单地假设计算时间与任务复杂度成正比
        return task_complexity / self.comp_resource
